package cc.rengu.igas.share.facade.bean.cups;

import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizException;

import java.util.Arrays;

/**
 * 域 125  QR用法子域TAG
 *
 * @author fangminwei
 * @date 2021/4/17
 */
@SuppressWarnings("AlibabaEnumConstantsMustHaveComment")
public enum F125_QR_SubTagEnum {
    _01("01", "qrScenceId", 3, "被扫消费即持卡人在商户端通过被扫的方式发起的消费交易"),
    _02("02", "payVoucher", 20, "被扫预授权即持卡人在商户端通过被扫的方式发起的预授权交易"),
    _03("03", "qrCode", 34, "主扫一般商户消费即持卡人在一般商户端通过主扫的方式发起的消费交易"),
    _04("04", "app1ServiceCodeId", 11, "主扫消费（限借记卡）即持卡人通过主扫的方式发起的限定非贷记帐户支付的消费，例如购买理财产品"),
    _05("05", "app2ServiceCodeId", 11, "主扫ATM取现"),
    _06("06", "acceptArea", 4, "主扫小微商户消费即持卡人在小微商户端通过主扫的方式发起的消费交易"),
    _07("07", "qrCodeByWay", 2, "一般消费（收款方T+0入账）"),
    _08("08", "riskPreventionAbility", 1, "限定非贷记账户支付的消费（收款方T+0入账）"),
    ;

    /**
     * 银联125域QR用法子域TAG名
     */
    private String cupsTagName;
    /**
     * 银联125域QR用法子域TAG名--》内部名称
     */
    private String innerTagName;
    /**
     * 银联125域QR用法子域TAG 值长度
     */
    private int length;
    /**
     * 描述
     */
    private String desc;

    F125_QR_SubTagEnum(String cupsTagName, String innerTagName, int length, String desc) {
        this.cupsTagName = cupsTagName;
        this.innerTagName = innerTagName;
        this.length = length;
        this.desc = desc;
    }

    public String getCupsTagName() {
        return cupsTagName;
    }

    public String getInnerTagName() {
        return innerTagName;
    }

    public int getLength() {
        return length;
    }

    public String getDesc() {
        return desc;
    }

    @Override
    public String toString() {
        return cupsTagName + "-" + innerTagName + "-" + desc;
    }

    /**
     * 通过内部tag名称获取枚举
     *
     * @param innerTagName 内部tag名称
     * @return 125域子域TAG的枚举
     */
    public static F125_QR_SubTagEnum findByInnerTagName(String innerTagName) {
        F125_QR_SubTagEnum result = Arrays.stream(F125_QR_SubTagEnum.values())
                .filter(e -> e.getInnerTagName().equals(innerTagName)).findFirst().orElse(null);

        if (result == null) {
            throw new BizException(OltpRpcdEnum.PARAM_IS_EMPTY_OR_NULL.getRespCode(), "找不到对应的枚举信息" + innerTagName);
        }
        return result;
    }

    /**
     * 通过银联tag名称获取枚举
     *
     * @param cupsTagName 银联tag名称
     * @return 125域子域TAG的枚举
     */
    public static F125_QR_SubTagEnum findByCupsTagName(String cupsTagName) {
        F125_QR_SubTagEnum result = Arrays.stream(F125_QR_SubTagEnum.values())
                .filter(e -> e.getCupsTagName().equals(cupsTagName)).findFirst().orElse(null);

        if (result == null) {
            throw new BizException(OltpRpcdEnum.PARAM_IS_EMPTY_OR_NULL.getRespCode(), "找不到对应的枚举信息" + cupsTagName);
        }
        return result;
    }
}
